from Reg import *

from condition_c import *


RegKeyword("auto")  
RegKeyword("double")      
RegKeyword("int")        
RegKeyword("struct")
RegKeyword("break")        
RegKeyword("else")        
RegKeyword("long")       
RegKeyword("switch")
RegKeyword("case")         
RegKeyword("enum")        
RegKeyword("register")   
RegKeyword("typedef")
RegKeyword("char")         
RegKeyword("extern")      
RegKeyword("return")     
RegKeyword("union")
RegKeyword("const")        
RegKeyword("float")       
RegKeyword("short")      
RegKeyword("unsigned")
RegKeyword("continue")     
RegKeyword("for")         
RegKeyword("signed")     
RegKeyword("void")
RegKeyword("default")      
RegKeyword("goto")        
RegKeyword("sizeof")     
RegKeyword("volatile")
RegKeyword("do")           
RegKeyword("if")          
RegKeyword("static")     
RegKeyword("while") 


RegKeyword("asm")
RegKeyword("bool")
RegKeyword("catch")
RegKeyword("class")
RegKeyword("const_cast")
RegKeyword("delete")
RegKeyword("dynamic_cast")
RegKeyword("explicit")
RegKeyword("export")
RegKeyword("false")
RegKeyword("friend")
RegKeyword("inline") 
RegKeyword("mutable")
RegKeyword("namespace")
RegKeyword("new")
RegKeyword("operator") 
RegKeyword("private")
RegKeyword("protected")
RegKeyword("public")
RegKeyword("reinterpret_cast")
RegKeyword("static_cast")
RegKeyword("template")
RegKeyword("this")
RegKeyword("throw")
RegKeyword("true")
RegKeyword("try")
RegKeyword("typeid")
RegKeyword("typename") 
RegKeyword("using")
RegKeyword("virtual")
RegKeyword("wchar_t") 



RegSymbol("(", "lparenthese")
RegSymbol(")", "rparenthese")
RegSymbol("[", "lbracket")
RegSymbol("]", "rbracket")
RegSymbol("{", "lbrace")
RegSymbol("}", "rbrace")
RegSymbol(",", "comma")
RegSymbol(".", "dot")
RegSymbol("?", "question")
RegSymbol(":", "colon")
RegSymbol(";", "semicolon")
RegSymbol("=", "operator_assign")
RegSymbol("#", "preprocess")

RegSymbol("*", "operator_indirection")
RegSymbol("&", "operator_addressof")
RegSymbol("+", "operator_plus")
RegSymbol("-", "operator_negation")
RegSymbol("*", "operator_multiplication")
RegSymbol("/", "operator_division")
RegSymbol("%", "operator_modulus")
RegSymbol("!", "operator_logical_negation")
RegSymbol(">", "operator_greater")
RegSymbol("<", "operator_less")
RegSymbol("!", "operator_not")
RegSymbol("&", "operator_bit_and")
RegSymbol("|", "operator_bit_or")
RegSymbol("^", "operator_bit_xor")
RegSymbol("~", "operator_bit_complement")

RegSymbol("<<=", "operator_left_shift_assign")
RegSymbol(">>=", "operator_right_shift_assign")
RegSymbol("->", "operator_arrow")
RegSymbol("+=", "operator_add_assign")
RegSymbol("-=", "operator_subtract_assign")
RegSymbol("*=", "operator_multiply_assign")
RegSymbol("/=", "operator_divide_assign")
RegSymbol("%=", "operator_modulus_assign")
RegSymbol("&=", "operator_bit_and_assign")
RegSymbol("^=", "operator_bit_exclusive_or_assign")
RegSymbol("!=", "operator_bit_inclusive_or_assign")
RegSymbol("<<", "operator_bit_left_shift")
RegSymbol(">>", "operator_bit_right_shift")
RegSymbol("==", "operator_equal")
RegSymbol("!=", "operator_notequal")
RegSymbol(">=", "operator_ge")
RegSymbol("<=", "operator_le")
RegSymbol("++", "operator_increment")
RegSymbol("--", "operator_decrement")
RegSymbol("&&", "operator_and")
RegSymbol("||", "operator_or")




@RegParser(id="string_noname", condition=is_double_quote)
def string_noname(content, offset):
    pre = offset
    offset += 1
    while offset >= 0 and offset < len(content):
        c = content[offset: offset+1]
        offset += 1
        if c == '"':
            break
        elif c == '\\':
            offset += 1
        
    return (True, content[pre: offset], offset, "tok_string")

@RegParser(id="char_noname", condition=is_single_quote)
def char_noname(content, offset):
    pre = offset
    offset += 1
    while offset >= 0 and offset < len(content):
        c = content[offset: offset+1]
        offset += 1
        if c == "'":
            break
        elif c == '\\':
            offset += 1
        
    return (True, content[pre: offset], offset, "tok_char")

@RegParser(id="identifier_noname", condition=is_letter_or_underline)
def identifier_noname(content, offset):
    pre = offset
    while offset >= 0:
        c = content[offset: offset+1]
        if c.isalpha() or c == "_" or c.isdigit():
            offset += 1
        else:
            break

    return (True, content[pre: offset], offset, "tok_identifier" )

@RegParser(id="number_noname", condition=is_number)
def number_noname(content, offset):
    pre = offset
    while offset >= 0:
        c = content[offset: offset+1]
        if c.isdigit():
            offset += 1
        else:
            break

    return (True, content[pre: offset], offset, "tok_number" )

@RegParser(id="block_comment", condition=is_block_comment)
def block_comment(content, offset):
    pre = offset

    offset += 2
    while offset >= 0 and offset < len(content):
        if "*/" == content[offset: offset+2]:
            break
        offset += 1
    offset += 2

    return (True, content[pre: offset], offset, "tok_block_comment" )


@RegParser(id="line_comment", condition=is_line_comment)
def line_comment(content, offset):
    pre = offset

    offset += 2
    while offset >= 0 and offset < len(content):
        if content[offset: offset+1] in ["\r", "\n"]:
            break
        if content[offset: offset+1] == "\\":
            offset += 1
        offset += 1

    return (True, content[pre: offset], offset, "tok_line_comment" )